var ns, UIAlbumBrowser, bmLocation;
app = new Vue({
    el: '#app',
    data: {
        list: [],
        form: {
            pageindex: 0,
            pagesize: 10,
            // status: 1, // 1-任务列表 2-新增记录
            PlanType: 1,
            TaskStatus:0//0-未开始,1-进行中,2-已结束
        },
        total: {
            ProcessCount: 0,
        },
        current_item_length: 0,
        is_searching: false,
        scroll_top: 0,
        can_scroll: false,
        showTop:false,
        showsearch:false,

    },
    methods: {
        get_data: function() {
            var that = this;
            that.is_searching= true,
            that.can_scroll = false;
            var options = {};
            options.action = "getequipmentlist";
            options.pagesize = that.form.pagesize;
            options.pageindex = that.form.pageindex;
            options.PlanType = that.form.PlanType;
            options.TaskStatus =that.form.TaskStatus;
            ns.post(options, function(succeed, data, err) {
                that.is_searching= false;
                if (succeed) {
                    if (data.list.length == that.form.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.form.pageindex == 0) {
                        that.list = data.list;

                    } else {
                        that.list = that.list.concat(data.list);
                    }
                    app.current_item_length = that.list.length
                    that.total.ProcessCount = data.ProcessCount;
                    
                } else if (err) {
                    // that.list = [];
                    that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        select_status: function(status) {
            var that = this;
            that.showTop=false;
            that.form.pageindex=0;
            that.form.TaskStatus = status;
            that.list = [];
            that.get_data();
        },
        open_list: function(item) {
            var that = this;
            var url = 'equipment_list_frm';
            var title = item.DevicePlanName;
            ns.openWin(url, title, {
                id: item.ID
            });
        },
        open_add: function () {
            var that = this;
            ns.openWin('equipment_addfrm', '新增记录');
        },
        open_select:function(){
            var that=this;
            that.showTop=!that.showTop;
        },
        doHideSearch:function(){
            var that=this;
            that.showTop=false;
            that.showsearch=false;
        },
        select_allstatus:function(){
            var that=this;
            that.showsearch=!that.showsearch;
        },
    },
    
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.get_data();
    api.addEventListener({
        name: 'devicetaskcomplete'
    }, function(ret, err) {
        app.get_data();
    });
    api.addEventListener({
        name: 'startplantaskdone'
    }, function(ret, err) {
        app.get_data();
    });
    api.addEventListener({
        name: 'do_open_add'
    }, function (ret, err) {
        app.open_add();
    });
    api.addEventListener({
        name: 'do_open_select'
    }, function (ret, err) {
        app.open_select();
    });
    ns.init_pull();
};

